Submitted By:            Armin K. <krejzi at email dot com>
Date:                    2012-12-30
Initial Package Version: 1.13.1
Upstream Status:         Not submitted.
Origin:                  Upstream mailing list.
Description:             Adds PRIME support to Xorg Server to make GPU offloading work.

--- xorg-server.orig/hw/xfree86/common/xf86Init.c	2012-10-14 01:38:50.000000000 +0200
+++ xorg-server/hw/xfree86/common/xf86Init.c	2012-12-01 19:51:53.249922134 +0100
@@ -361,6 +361,16 @@
     return ret;
 }
 
+extern void xf86AutoConfigOutputDevice(ScrnInfoPtr pScrn, ScrnInfoPtr master);                              
+static void
+xf86AutoConfigOutputDevices(void)
+{
+    int i;
+
+    for (i = 0; i < xf86NumGPUScreens; i++)
+        xf86AutoConfigOutputDevice(xf86GPUScreens[i], xf86Screens[0]);
+}
+
 static void
 InstallSignalHandlers(void)
 {
@@ -927,6 +937,8 @@
     for (i = 0; i < xf86NumGPUScreens; i++)
         AttachUnboundGPU(xf86Screens[0]->pScreen, xf86GPUScreens[i]->pScreen);
 
+    xf86AutoConfigOutputDevices();
+
     xf86VGAarbiterWrapFunctions();
     if (sigio_blocked)
         OsReleaseSIGIO();
--- xorg-server.orig/hw/xfree86/common/xf86platformBus.c	2012-11-02 05:17:59.000000000 +0100
+++ xorg-server/hw/xfree86/common/xf86platformBus.c	2012-12-01 19:51:53.249922134 +0100
@@ -387,6 +387,8 @@
     return foundScreen;
 }
 
+extern void xf86AutoConfigOutputDevice(ScrnInfoPtr pScrn, ScrnInfoPtr master);
+
 int
 xf86platformAddDevice(int index)
 {
@@ -446,6 +448,7 @@
 
    /* attach unbound to 0 protocol screen */
    AttachUnboundGPU(xf86Screens[0]->pScreen, xf86GPUScreens[i]->pScreen);
+   xf86AutoConfigOutputDevice(xf86GPUScreens[i], xf86Screens[0]);
 
    return 0;
 }
--- xorg-server.orig/hw/xfree86/modes/xf86Crtc.c	2012-10-14 01:38:50.000000000 +0200
+++ xorg-server/hw/xfree86/modes/xf86Crtc.c	2012-12-01 19:51:53.250922153 +0100
@@ -3258,3 +3258,31 @@
             crtc->x = crtc->y = 0;
         }
 }
+
+
+void xf86AutoConfigOutputDevice(ScrnInfoPtr pScrn, ScrnInfoPtr master)
+{
+    RRProviderPtr master_provider;
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(master);
+    xf86CrtcConfigPtr slave_config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+    if (!config || !slave_config)
+        return;
+
+    master_provider = config->randr_provider;
+
+    if ((master->capabilities & RR_Capability_SinkOffload) &&
+        pScrn->capabilities & RR_Capability_SourceOffload) {
+            /* source offload */
+            
+        DetachUnboundGPU(pScrn->pScreen);
+        AttachOffloadGPU(master->pScreen, pScrn->pScreen);
+        slave_config->randr_provider->offload_sink = master_provider;
+    } else if ((master->capabilities & RR_Capability_SourceOutput) &&
+               pScrn->capabilities & RR_Capability_SinkOutput) {
+        /* sink offload */
+        DetachUnboundGPU(pScrn->pScreen);
+        AttachOutputGPU(master->pScreen, pScrn->pScreen);
+        slave_config->randr_provider->output_source = master_provider;
+    }
+}
